home *** CD-ROM | disk | FTP | other *** search
- '
- ' MODEM_IO.BAS
- '
-
- '$INCLUDE: 'MODEM_IO.BI'
- '$INCLUDE: 'PCL4B.BI'
-
- CONST FALSE = 0
- CONST TRUE = NOT FALSE
-
- ' echos incoming to screen
-
- ' send string to modem & get echo
-
- ' wait for Text$
-
- ' enter command state
- ' NOTE: assumes escape char = '+' & guard time = 1 sec
-
- ' hangup phone (in command state)
-
- ' wait for continuous quiet (no incoming serial data)
-
-
- Function BreakTest ()
- ' User BREAK ?
- If SioBrkKey() Or SioKeyPress() Then
- Print "User BREAK"
- BreakTest = True
- Exit Function
- End If
- BreakTest = False
- End Function
-
- Function ModemCmdState (ByVal Port)
- ' delay a bit over 1 second
- rc = SioDelay(25)
- ' send Escape Code exactly 3 times
- For I = 1 To 3
- rc = SioPutc(Port, Asc("+"))
- rc = SioDelay(5)
- Next I
- ' delay again
- rc = SioDelay(25)
- End Function
-
- Function ModemEcho (ByVal Port, ByVal Echo)
- Time& = SioTimer&()
- Do While SioTimer&() < Time & Echo
- rc = SioGetc(Port, 1)
- If rc >= 0 Then rc = SioCrtWrite(rc)
- Loop
- End Function
-
- Function ModemHangup (ByVal Port)
- ' enter command state
- rc = ModemCmdState(Port)
- ' hangup !
- rc = ModemSendTo(Port, 4, "!AT!")
- rc = ModemEcho(Port, 10)
- rc = ModemSendTo(Port, 4, "ATH0!")
- End Function
-
- Function ModemQuiet (ByVal Port, ByVal Tics)
- ' set up
- CharTime& = SioTimer&()
- Do
- ' User BREAK ?
- If BreakTest() Then
- ModemQuiet = False
- Exit Function
- End If
- ' wait for next character
- Code = SioGetc(Port, 1)
- If Code < -1 Then
- ModemQuiet = False
- Exit Function
- End If
- If Code >= 0 Then
- CharTime& = SioTimer&()
- rc = SioCrtWrite(Code)
- Else
- ' =-1, timed out
- If SioTimer&() >= CharTime& + Tics Then
- ModemQuiet = True
- Exit Function
- End If
- End If
- Loop
- End Function
-
- Function ModemSendTo (ByVal Port, ByVal Pace, Text$)
- For I = 1 To Len(Text$)
- ' User BREAK ?
- If BreakTest() Then
- ModemSendTo = False
- Exit Function
- End If
- ' delay <Pace> tics
- If Pace > 0 Then rc = ModemEcho(Port, Pace)
- ' fetch character
- c$ = Mid$(Text$, I, 1)
- Select Case c$
- Case "!"
- ' replace ! with carriage return
- c$ = Chr$(13)
- Case "~"
- ' delay 1/2 second
- rc = SioDelay(10)
- c$ = " "
- Case " "
- ' delay 1/4 second
- rc = SioDelay(5)
- c$ = " "
- End Select
- ' transmit
- rc = SioPutc(Port, Asc(c$))
- Next I
- ModemSendTo = True
- End Function
-
- Function ModemWaitFor (ByVal Port, ByVal Tics, ByVal CaseFlag, Text$)
- Length = Len(Text$)
- ' wait for string
- Time& = SioTimer&()
- First = 1
- Do While SioTimer&() < Time & Tics
- ' User BREAK ?
- If BreakTest() Then
- ModemWaitFor = False
- Exit Function
- End If
- ' wait for next character
- Code = SioGetc(Port, 1)
- If Code < -1 Then
- ModemWaitFor = False
- Exit Function
- End If
- If Code >= 0 Then
- ' echo char
- rc = SioCrtWrite(Code)
- ' prepare chars
- c1$ = Mid$(Text$, First, 1)
- First = First + 1
- c2$ = Chr$(Code)
- ' case sensitive ?
- If Not CaseFlag Then
- c1$ = UCase$(c1$)
- c2$ = UCase$(c2$)
- End If
- ' does char match ?
- '''PRINT "[";c1$;"|";c2$;"]"
- If c1$ = c2$ Then
- If First > Length Then
- ModemWaitFor = True
- Exit Function
- End If
- Else
- 'start over again
- First = 1
- End If
- End If
- Loop
- ModemWaitFor = False
- End Function
-
-